package com.gaotu.demo;

import lombok.*;

import java.util.Date;


@Data
public class User {
    private Long id;
    private Date createTime;
    private Date updateTime;

    private UserStatus status;
    private String name;
    private String password;

    public static User apply(UserStatus status, String name, String password){
        User user = new User();
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());

        user.setStatus(status);
        user.setName(name);
        user.setPassword(password);
        return user;
    }

    public boolean checkPassword(String password){
        return getPassword().equals(password);
    }

    public void modifyPassword(String oldPassword, String newPassword){
        if (!checkPassword(oldPassword)){
            throw new PasswordNotMatchException();
        }
        setPassword(newPassword);
        setUpdateTime(new Date());
    }
}